<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>{{msg}}</h1>
        <button @click="changeMsg">改变消息</button>
    </div>
    <script src="vue.js"></script>
    <script>
        let vm = new Vue({
            el: "#app",
            data: {
                msg: "消息"
            },
            // 可以捕获值的改变
            watch: {
                msg: function (newValue, oldValue) {
                    console.log("新数据的值：" + newValue, '老数据的值：' + oldValue);
                }
            },
            methods: {
                changeMsg: function () {
                    this.msg = "这是一个新消息"
                }
            },
        })
    </script>
</body>

</html>